home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Misc / bgui / Examples / Source / IDCMPHook.c < prev    next >
C/C++ Source or Header  |  2000-05-09  |  6KB  |  177 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/examples/IDCMPHook.c,v 41.11 2000/05/09 20:33:38 mlemos Exp $
  3.  *
  4.  * IDCMPHook.c
  5.  *
  6.  * (C) Copyright 1998 Manuel Lemos.
  7.  * (C) Copyright 1995 Jaba Development.
  8.  * (C) Copyright 1995 Jan van den Baard.
  9.  * All Rights Reserved.
  10.  *
  11.  * $Log: IDCMPHook.c,v $
  12.  * Revision 41.11  2000/05/09 20:33:38  mlemos
  13.  * Bumped to revision 41.11
  14.  *
  15.  * Revision 1.2  2000/05/09 19:58:56  mlemos
  16.  * Merged with the branch Manuel_Lemos_fixes.
  17.  *
  18.  * Revision 1.1.2.2  1999/02/19 05:03:54  mlemos
  19.  * Added support to build with Storm C.
  20.  *
  21.  * Revision 1.1.2.1  1998/02/28 17:45:20  mlemos
  22.  * Ian sources
  23.  *
  24.  *
  25.  */
  26.  
  27. /* Execute me to compile with DICE V3.0
  28. dcc IDCMPHook.c -proto -mi -ms -mRR -lbgui
  29. quit
  30. */
  31.  
  32. #include "DemoCode.h"
  33.  
  34. /*
  35. **      Object ID.
  36. **/
  37. #define ID_QUIT                 1
  38.  
  39. /*
  40. **      "tick" counter for the hook.
  41. **/
  42. UBYTE   Ticks = 0;
  43.  
  44. /*
  45. **      Simple example of the hook code.
  46. **/
  47. #ifdef __STORM__
  48. VOID SAVEDS ASM
  49. #else
  50. SAVEDS ASM VOID
  51. #endif
  52. hookFunc( REG(a0) struct Hook *hook, REG(a2) Object *obj, REG(a1) struct IntuiMessage *imsg )
  53. {
  54.         struct Window                   *wptr = NULL;
  55.  
  56.         /*
  57.         **      This hook is a simple IDCMP_INTUITICKS hook.
  58.         **      More complex hooks can receive several message
  59.         **      types depending on the setting of the
  60.         **      WINDOW_IDCMPHookBits attribute.
  61.         **
  62.         **      Simply beep the screen
  63.         **      every two seconds or so
  64.         **      while the window is active.
  65.         **/
  66.         if ( Ticks == 20 ) {
  67.                 Ticks = 0;
  68.                 /*
  69.                 **      Only flash the screen on which
  70.                 **      the window is located.
  71.                 **/
  72.                 GetAttr( WINDOW_Window, obj, ( ULONG * )&wptr );
  73.                 if ( wptr )
  74.                         DisplayBeep( wptr->WScreen );
  75.         }
  76.         Ticks++;
  77. }
  78.  
  79.  
  80. /*
  81. **      The hook structure.
  82. **
  83. ** typedef unsigned long (*HOOKFUNC)();
  84. **/
  85. struct Hook idcmpHook = { NULL, NULL, (HOOKFUNC)hookFunc, NULL, NULL };
  86.  
  87. VOID StartDemo( void )
  88. {
  89.         struct Window           *window;
  90.         Object                  *WO_Window, *GO_Quit;
  91.         ULONG                    signal = 0, rc;
  92.         BOOL                     running = TRUE;
  93.  
  94.         /*
  95.         **      Create the window object.
  96.         **/
  97.         WO_Window = WindowObject,
  98.                 WINDOW_Title,           "IDCMPHook Demo",
  99.                 WINDOW_SizeGadget,      FALSE,
  100.                 WINDOW_RMBTrap,         TRUE,
  101.                 WINDOW_IDCMP,           IDCMP_INTUITICKS,
  102.                 WINDOW_IDCMPHookBits,   IDCMP_INTUITICKS,
  103.                 WINDOW_IDCMPHook,       &idcmpHook,
  104.                 WINDOW_AutoAspect,      TRUE,
  105.                 WINDOW_MasterGroup,
  106.                         /*
  107.                         **      A simple vertical group
  108.                         **      containing a descriptive text
  109.                         **      and a "Quit" button.
  110.                         **/
  111.                         VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ), GROUP_BackFill, SHINE_RASTER,
  112.                                 StartMember, InfoFixed( NULL, "\33cThis small demo has a IDCMP-hook\n"
  113.                                                               "installed which will flash the\n"
  114.                                                               "display every two seconds while the\n"
  115.                                                               "window is active.", NULL, 4 ), EndMember,
  116.                                 StartMember,
  117.                                         HGroupObject,
  118.                                                 VarSpace( DEFAULT_WEIGHT ),
  119.                                                 StartMember, GO_Quit  = KeyButton( "_Quit",  ID_QUIT  ), EndMember,
  120.                                                 VarSpace( DEFAULT_WEIGHT ),
  121.                                         EndObject,
  122.                                 EndMember,
  123.                         EndObject,
  124.         EndObject;
  125.  
  126.         /*
  127.         **      Object created OK?
  128.         **/
  129.         if ( WO_Window ) {
  130.                 /*
  131.                 **      Assign a key to the button.
  132.                 **/
  133.                 if ( GadgetKey( WO_Window, GO_Quit,  "q" )) {
  134.                         /*
  135.                         **      try to open the window.
  136.                         **/
  137.                         if ( window = WindowOpen( WO_Window )) {
  138.                                 /*
  139.                                 **      Obtain it's wait mask.
  140.                                 **/
  141.                                 GetAttr( WINDOW_SigMask, WO_Window, &signal );
  142.                                 /*
  143.                                 **      Event loop...
  144.                                 **/
  145.                                 do {
  146.                                         Wait( signal );
  147.                                         /*
  148.                                         **      Handle events.
  149.                                         **/
  150.                                         while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  151.                                                 /*
  152.                                                 **      Evaluate return code.
  153.                                                 **/
  154.                                                 switch ( rc ) {
  155.  
  156.                                                         case    WMHI_CLOSEWINDOW:
  157.                                                         case    ID_QUIT:
  158.                                                                 running = FALSE;
  159.                                                                 break;
  160.                                                 }
  161.                                         }
  162.                                 } while ( running );
  163.                         } else
  164.                                 Tell( "Could not open the window\n" );
  165.                 } else
  166.                         Tell( "Could not assign gadget key\n" );
  167.                 /*
  168.                 **      Disposing of the window object will
  169.                 **      also close the window if it is
  170.                 **      already opened and it will dispose of
  171.                 **      all objects attached to it.
  172.                 **/
  173.                 DisposeObject( WO_Window );
  174.         } else
  175.                 Tell( "Unable to create the window object\n" );
  176. }
  177.